package com.hnkywl.sts.action.base;

import com.hnkywl.sts.entity.base.Fwpz;
import com.hnkywl.sts.service.base.FwpzService;
import net.ruixin.web.struts2.SimpleActionSupport;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * Created with IntelliJ IDEA.
 * User: lenovo
 * Date: 13-5-21
 * Time: 下午2:49
 * To change this template use File | Settings | File Templates.
 */
@Namespace("/base/fwpz")
public class FwpzAction extends SimpleActionSupport {
    private FwpzService fwpzService;
    private Fwpz fwpz;
    //查询条件
    private String name;
    private String action;
    //分页组件 起始位置
    private int page;
    //分页组件 页面大小
    private int rows;
    private Long fwpzId;
    /**
     * 服务配置分页查询
     */
    @Action("fwpzList")
    public void fwpzList() {
        this.renderJson(this.fwpzService.findAllFwpz(name,action,page, rows));
    }

    /**
     *   判断增加修改
     */
    @Action("fwpz_content")
    public String sjzdsyContent() {
        //进入update页面
        if (fwpzId != null){
            fwpz = fwpzService.findFwpzDetail(fwpzId);
        }else{
            //进入add页面
            fwpz = new Fwpz();
        }
        return SUCCESS;
    }
    /**
     * 添加服务配置信息
     */
    @Action("add_fwpz")
    public void addFwpz() {
        try {
            this.fwpzService.saveFwpz(fwpz);
            renderText("{\"statusCode\":\"200\", \"message\":\"添加服务配置成功！\", \"operationType\":\"add\"}");
        } catch (Exception e) {
            e.printStackTrace();
            renderText("{\"statusCode\":\"300\", \"message\":\"" + e.getMessage() + "\"}");
        }
    }

    /**
     * 删除服务配置信息
     */
    @Action("delete_fwpz")
    public void deleteFwpz() {
        try {
            this.fwpzService.deleteFwpz(fwpzId);
            renderText("{\"statusCode\":\"200\", \"message\":\"删除服务配置成功！\", \"operationType\":\"delete\"}");
        } catch (Exception e) {
            e.printStackTrace();
            renderText("{\"statusCode\":\"300\", \"message\":\"" + e.getMessage() + "\"}");
        }
    }

    /**
     * 更改服务配置信息
     */
    @Action("update_fwpz")
    public void updateFwpz() {
        try {
            this.fwpzService.updateFwpz(fwpz);
            renderText("{\"statusCode\":\"200\",\"message\":\"修改服务配置成功！\"}");
        } catch (RuntimeException e) {
            e.printStackTrace();
            renderText("{\"statusCode\":\"300\", \"message\":\"" + e.getMessage() + "\"}");
        }
    }
    //=========getter=====setter==================

    public Fwpz getFwpz() {
        return fwpz;
    }

    public void setFwpz(Fwpz fwpz) {
        this.fwpz = fwpz;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAction() {
        return action;
    }

    public void setAction(String action) {
        this.action = action;
    }

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public int getRows() {
        return rows;
    }

    public void setRows(int rows) {
        this.rows = rows;
    }

    public Long getFwpzId() {
        return fwpzId;
    }

    public void setFwpzId(Long fwpzId) {
        this.fwpzId = fwpzId;
    }

    @Autowired
    public void setFwpzService(FwpzService fwpzService) {
        this.fwpzService = fwpzService;
    }
}
